package com.ruoyi.business.controller;

import com.ruoyi.business.approvalflow.service.ITRegisterApprovalLevelConfigService;
import com.ruoyi.business.approvalflow.vo.TRegisterApprovalLevelConfigVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 审批级别配置Controller
 *
 * @author Tellsea
 * @date 2025-06-22
 */
@Api(tags = "审批级别配置Controller")
@RestController
@RequestMapping("/business/registerApprovalLevelConfig")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TRegisterApprovalLevelConfigController extends BaseController {

    private final ITRegisterApprovalLevelConfigService tRegisterApprovalLevelConfigService;

    @ApiOperation("查询审批级别配置列表")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:list')")
    @GetMapping("/list")
    public TableDataInfo<TRegisterApprovalLevelConfigVo> list(TRegisterApprovalLevelConfigVo entity) {
        return tRegisterApprovalLevelConfigService.queryList(entity);
    }

    @ApiOperation("查询审批级别配置所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TRegisterApprovalLevelConfigVo entity) {
        return AjaxResult.success("查询成功", tRegisterApprovalLevelConfigService.queryAll(entity));
    }

    @ApiOperation("导出审批级别配置列表")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:export')")
    @Log(title = "审批级别配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRegisterApprovalLevelConfigVo entity) {
        List<TRegisterApprovalLevelConfigVo> list = tRegisterApprovalLevelConfigService.queryAll(entity);
        ExcelUtil<TRegisterApprovalLevelConfigVo> util = new ExcelUtil<>(TRegisterApprovalLevelConfigVo.class);
        util.exportExcel(response, list, "审批级别配置数据");
    }

    @ApiOperation("获取审批级别配置详细信息")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:query')")
    @GetMapping(value = "/getInfo/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") String levelId) {
        return AjaxResult.success("查询成功", tRegisterApprovalLevelConfigService.queryById(levelId));
    }

    @ApiOperation("新增审批级别配置")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:add')")
    @Log(title = "审批级别配置", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TRegisterApprovalLevelConfigVo entity) {
        return toAjax(tRegisterApprovalLevelConfigService.save(entity));
    }

    @ApiOperation("修改审批级别配置")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:edit')")
    @Log(title = "审批级别配置", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TRegisterApprovalLevelConfigVo entity) {
        return toAjax(tRegisterApprovalLevelConfigService.updateById(entity));
    }

    @ApiOperation("删除审批级别配置")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalLevelConfig:remove')")
    @Log(title = "审批级别配置", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{levelIds}")
    public AjaxResult remove(@PathVariable String[] levelIds) {
        return toAjax(tRegisterApprovalLevelConfigService.removeByIds(Arrays.asList(levelIds)) ? 1 : 0);
    }
}
